import { Provide } from '@midwayjs/decorator'
import { BaseService } from '@cool-midway/core'
import { InjectEntityModel } from '@midwayjs/typeorm'
import type { Repository } from 'typeorm'
import { BannerInfoEntity } from './../entity/info'

@Provide()
export class BannerInfoService extends BaseService {
  @InjectEntityModel(BannerInfoEntity)
  bsannerInfoEntity: Repository<BannerInfoEntity>

  async detail({ id }) {
    return this.bsannerInfoEntity.findOneBy({ id })
  }

  /**
   * 执行sql分页
   */
  async sqlPage(query) {
    return this.sqlRenderPage(
      'select * from news_info ORDER BY id ASC',
      query,
      false,
    )
  }

  /**
   * 执行entity分页
   */
  async entityPage(query) {
    const find = this.bsannerInfoEntity.createQueryBuilder()
    return this.entityRenderPage(find, query)
  }
}
